#include<iostream>
#include<cstring>
using namespace std;
//这道题比较坑，注意这里1和9开头的电话号码，都是非法的！！！
class CTelNumber
{
    private:
        char *number;
    public:
        CTelNumber(const char *num=NULL)
        {
            if(num)
            {
                number=new char[strlen(num)+1];
                strcpy(number,num);
            }
            else
            {
                number=new char[1];
                number[0]='\0';
            }
        }
        CTelNumber(const CTelNumber& s)
        {
            if(s.number)
            {
                number=new char[strlen(s.number)+2];
                if(s.number[0]=='5' ||s.number[0]=='6' || s.number[0]=='7' || s.number[0]=='8')
                {
                    number[0]='2';
                    strcpy(number+1,s.number);
                }
                else if(s.number[0]=='2' || s.number[0]=='3' || s.number[0]=='4')
                {
                    number[0]='8';
                    strcpy(number+1,s.number);
                }
                else
                {
                    strcpy(number,s.number);
                }
            }
            else
            {
                number=new char[1];
                number[0]='\0';
            }
        }

        ~CTelNumber()
        {
            if(number)
                delete[] number;
        }
        void Print()
        {
            cout<<number<<endl;
        }
};

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        char *num=new char[8];
        cin>>num;
        int flag=0;
        for(int i=0;i<strlen(num);i++)
        {
            if(num[i]>='0' && num[i]<='9')
            {
                flag=0;
            }
            else
            {
                flag=1;
                break;
            }
        }
        if(strlen(num)!=7 || flag==1 ||num[0]<='1'||num[0]>='9' )
        {
            cout<<"Illegal phone number"<<endl;
        }
        else
        {
            CTelNumber tmp(num);
            CTelNumber ans(tmp);
            ans.Print();
        }
        delete[] num;
    }
}